<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>查看学生成绩</title>
<link href="${pageContext.request.contextPath}/static/bootstrap-3.3.7-dist/css/bootstrap.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/static/bootstrap-3.3.7-dist/css/bootstrap-table.css" rel="stylesheet">
<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/jquery-3.3.1.js"></script>
<script	type="text/javascript" src="${pageContext.request.contextPath}/static/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
<script	type="text/javascript" src="${pageContext.request.contextPath}/static/bootstrap-3.3.7-dist/js/bootstrap-table.js"></script>
<script	type="text/javascript" src="${pageContext.request.contextPath}/static/bootstrap-3.3.7-dist/locale/bootstrap-table-zh-CN.js"></script>
</head>
<script type="text/javascript">
	$(function(){
		$("#table").bootstrapTable("refresh");
		getList();
		$.ajax({
			url:"${pageContext.request.contextPath}/StudentScore",
			dataType:"json",
			type:"post",
			success:function(data){
				$("[name='select']").html("<option value=''>请选择</option>");
				for(var i in data.list1){
					$("[name='select']").append("<option value='"+data.gradename+data.list1[i].gradename+"'>"+data.gradename+data.list1[i].gradename+"</option>")
				}
			}
		})	
	})

	function getList(){
		$("#table").bootstrapTable({
			url:"${pageContext.request.contextPath}/StudentScore",
			toolbar:"#toolbar",
			method:"post",
			dataType:"json",
			sidePagination:"server",
			pagination : true,//设置为 true 会在表格底部显示分页条
			paginationLoop : true,//设置为 true 启用分页条无限循环的功能。
			pageNumber:1,
			pageSize:3,
			pageList:[ 3, 6, 9],
			contentType:"application/x-www-form-urlencoded",
			queryParamsType : "",
			//请求服务器数据
			queryParams : queryParams,
			columns:[
				{
					checkbox:true
				},
				{
					field:"id",
					title:"编号",
					align:"center"
				},
				{
					field:"realName",
					title:"姓名",
					align:"center"
				},
				{
					field:"studentNum",
					title:"学号",
					align:"center"
				},
				{
					field:"gradeClass",
					title:"年班级",
					align:"center"
				},
				{
					field:"chineseScore",
					title:"语文成绩",
					align:"center"
				},
				{
					field:"mathScore",
					title:"数学成绩",
					align:"center"
				},
				{
					field:"englishScore",
					title:"英语成绩",
					align:"center"
				},
				{
					field:"chemistryScore",
					title:"化学成绩",
					align:"center"
				},
				{
					field:"physicsScore",
					title:"物理成绩",
					align:"center"
				},
				{
					field:"biologyScore",
					title:"生物成绩",
					align:"center"
				},
				{
					field:"count",
					title:"总分",
					align:"center"
				},
				{
					field:"total",
					title:"总科目",
					align:"center"
				}
			]
		})
	}
	function queryParams(params){
		var likeName=$("[name='likeName']").val();
		var likeClass=$("[name='select']").val();
		var param={
			pageNumber:params.pageNumber-1,
			pageSize:params.pageSize,
			likeName:likeName,
			likeClass:likeClass
			
		}
		return param;
	}
	function Upd(){
		var row=$("#table").bootstrapTable('getSelections');
		if(row[0]==null){
			alert("请选中一行进行修改");
		}else{
				var id =row[0].id;
		       var realname=row[0].realName;
		       var studentNum=row[0].studentNum;
		       var gradeClass=row[0].gradeClass;
		       console.log(gradeClass);
		       var chineseScore=row[0].chineseScore;
		       var mathScore=row[0].mathScore;
		       var englishScore=row[0].englishScore;
		       var chemistryScore=row[0].chemistryScore;
		       var physicsScore=row[0].physicsScore;
		       var biologyScore=row[0].biologyScore;
		       $("[name='id']").val(id);
		     $("[name='realname']").val(realname);
		     $("[name='studentNum']").val(studentNum);
		     $("[name='gradename']").val(gradeClass);
		     $("[name='ChineseScore']").val(chineseScore);
		     $("[name='MathScore']").val(mathScore);
		     $("[name='EnglishScore']").val(englishScore);
		     $("[name='ChemistryScore']").val(chemistryScore);
		     $("[name='PhysicsScore']").val(physicsScore);
		     $("[name='BiologyScore']").val(biologyScore);
		}
       
	}
	function upd(){
			var likeName=$("#realname").val();/*模糊查询  */
			var id= $("[name='id']").val();
			var realname= $("[name='realname']").val();
		 	var studentNum=$("[name='studentNum']").val();
		 	var gradeClass=$("[name='gradename']").val();
		 	var ChineseScore=$("[name='ChineseScore']").val();
		 	var MathScore=$("[name='MathScore']").val();
		 	var EnglishScore=$("[name='EnglishScore']").val();
		 	var ChemistryScore=$("[name='ChemistryScore']").val();
		 	var PhysicsScore=$("[name='PhysicsScore']").val();
		 	var BiologyScore=$("[name='BiologyScore']").val();
		 	$.ajax({
				url:"${pageContext.request.contextPath}/UpdateStudentScore",
				dataType:"json",
				type:"post",
				data:{
					likeName:likeName,
					id:id,
					realname:realname,
					studentNum:studentNum,
					gradeClass:gradeClass,
					ChineseScore:ChineseScore,
					MathScore:MathScore,
					EnglishScore:EnglishScore,
					ChemistryScore:ChemistryScore,
					PhysicsScore:PhysicsScore,
					BiologyScore:BiologyScore
				},
				success:function(data){
					if(data){
						alert("修改成功");
						$("#table").bootstrapTable("refresh");
					}else{
						alert("修改失败");
					}
				}
			})	
	}
	function refresh(){
		var likeName=$("[name='likeName']").val();
		var likeClass=$("[name='select']").val();
		console.log(likeName);
		console.log(likeClass);
		$.ajax({
			url:"${pageContext.request.contextPath}/StudentScore",
			dataType:"json",
			type:"post",
			data:{
				likeName:likeName,
				likeClass:likeClass
			},
			 success:function(data){
				 $("#table").bootstrapTable("refreshOptions",{pageNumber:1});
			}  
		})	
	}
</script>
<style>
	#modalP{
		padding:10px;
		width:500px;
		height:55px;
		margin:0 auto;
		line-height:55px;
		font-size:15px;
	}
	#modalP>input{
		width:300px;
		height:30px;
	}
	.modalSpan{
		display:inline-block;
		width:100px;
		height:30px;
		line-height:30px;
		text-align:right;
	}
</style>
<body>
<div class="col-sm-12 col-md-12">
		<div class="main-container">
		<div class="panel panel-default" style="margin: 0;padding: 0" id="ST">
			<div class="panel-heading">搜索</div>
			<div class="panel-body" >
				<form role="form" class="form-inline">
					<div class="form-group">学生姓名：</div>
					<input name="likeName" type="text" class="form-control input-sm"
						placeholder=""> &nbsp;
					<div class="form-group">班级:</div>
					<select name="select" class="form-control input-sm">
						<option value="">-请选择-</option>
					</select>
					<div class="form-group">
						<button class="btn btn-reset glyphicon glyphicon-search"
							type="button" onclick="reset()">清空</button>
					</div>
					<div class="form-group">
						<button class="btn btn-success glyphicon glyphicon-search"
							type="button" onclick="refresh()">搜索</button>
					</div>
				</form>
					</div>
		</div>
			<div id="toolbar">
				<button class="btn btn-primary btn-gt glyphicon glyphicon glyphicon-circle-arrow-up" data-toggle="modal"  data-target="#upd" onclick="Upd()">修改</button>
			</div>
			<table id="table" ></table>
			<!--修改模态框  -->
			<div class="modal fade" id="upd" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" >
			    <div class="modal-dialog">
			        <div class="modal-content">
			            <div class="modal-header">
			                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
			                <h4 class="modal-title" id="myModalLabel">修改学生成绩信息</h4>
			            </div>
			            <div class="modal-body">
			            	<p id="modalP">
			            		<span class="modalSpan">编号:</span>
			            		<input type="text" name="id" readonly="readonly" />
			            	</p>
			            	<p id="modalP">
			            		<span class="modalSpan">姓名:</span>
			            		<input type="text" name="realname" readonly="readonly" />
			            	</p>
			            	<p id="modalP">
			            		<span class="modalSpan">学号:</span>
			            		<input type="text" name="studentNum" readonly="readonly" />
			            	</p>
			            	<p id="modalP">
			            		<span class="modalSpan">所在年班级:</span>
			            		<input type="text" name="gradename" readonly="readonly" />
			            	</p>
			            	<p id="modalP">
			            		<span class="modalSpan">语文成绩:</span>
			            		<input type="text" name="ChineseScore" />
			            	</p>
			            	<p id="modalP">
			            		<span class="modalSpan">数学成绩:</span>
			            		<input type="text" name="MathScore" />
			            	</p>
			            	<p id="modalP">
			            		<span class="modalSpan">英语成绩:</span>
			            		<input type="text" name="EnglishScore" />
			            	</p>
			            	<p id="modalP">
			            		<span class="modalSpan">化学成绩:</span>
			            		<input type="text" name="ChemistryScore" />
			            	</p>
			            	<p id="modalP">
			            		<span class="modalSpan">物理成绩:</span>
			            		<input type="text" name="PhysicsScore" />
			            	</p>
			            	<p id="modalP">
			            		<span class="modalSpan">生物成绩:</span>
			            		<input type="text" name="BiologyScore" />
			            	</p>
			      
			            	
			            </div>
			            <div class="modal-footer">
			                <button type="button" class="btn btn-default" data-dismiss="modal" >关闭</button>
			                <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="upd()">提交</button>
			            </div>
			        </div>
			    </div>
			</div>
			
			
		</div>
	</div>
</body>

</html>
